/*
 * @Author: zhangyang
 * @Date: 2021-11-14 15:40:23
 * @LastEditTime: 2021-11-14 16:43:42
 * @Description:  鉴权
 */
'use strict';

module.exports = (options) =>{
  /**
   * @param {Egg.Context} ctx 增加注解只是为了获取编辑器提示
   */
  return async (ctx, next)=>{
    /**
     *  免鉴权白名单
     */
    const whiteList = ['10000/1'];
    const { com, task, aid } = ctx.get_params();
    const token = ctx.cookies.get('token');
    const route = `${com}/${task}`;
    if (!whiteList.includes(route)) {
      let tips = '';
      // 判断是否拥有token
      if (!token) {
        tips = console.log(ctx.young_response({
          status: -1,
          msg: '登录信息过期，请重新登录'
        }));
      }
      // 不存在于白名单之中，进行鉴权
      ctx.body = `<h1>暂无权限，请联系管理员授权</h1>`;
      return;
    }
    await next();
  }

};